package com.xjl.service.impl;

import java.util.List;

import com.xjl.dao.AdminDao;
import com.xjl.dao.impl.AdminDaoImpl;
import com.xjl.demo.Admin;
import com.xjl.service.AdminService;

public class AdminServiceImpl implements AdminService{
	//定义一个数据访问层admindao对象，组合dao类函数
	AdminDao admindao = new AdminDaoImpl();
	//管理员登录校验
	public Admin CheckAdminLoginService(int adminid, String adminpwd) throws Exception {
		return admindao.CheckAdminLoginDao(adminid, adminpwd);
	}

	
	//修改用户密码
	public int ChangeAdminPwdService(int adminid, String adminpwd, String newpwd) {
		int index =-1;
		try {
			Admin admin = admindao.CheckAdminLoginDao(adminid, adminpwd);
			if(admin!=null){
				index = admindao.ChangeAdminPwdDao(admin, newpwd);
			}else{
				index = -1;
			}
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return index;
	}

	//查询所有管理员的信息
	public List<Admin> SelectAllAdmin() {
		
		return admindao.SelectAllAdmin();
	}


	//删除管理员
	public int DeleleAdmin(int adminid) {
		int index = admindao.SelectAdminById(adminid);
		if(index==1){
			return admindao.DeleteAdminById(adminid);
		}else if(index==0){
			return -1;
		}else{
			return 0;
		}
		
	}


	@Override
	public int InsertAdminService(Admin admin) {
		int index = admindao.SelectAdminById(admin.getAdminid());
		if(index==0){
			return admindao.InsertnewAdminDao(admin);
		}else if(index==1){
			return -1;
			
		}else{
			return -1;
		}
		
	}

}
